package com.xiaoxu.spark.tuning

import com.xiaoxu.spark_base.example.RDD.CreateRDD.conf
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.sql.SparkSession
import org.apache.spark.storage.StorageLevel

import scala.collection.mutable.ArrayBuffer

object SerializerTypeDemo {

  case class Person(name: String, age: Int, sex: String, hobby: String)

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      //conf.registerKryoClasses(Array(classOf[Person]))

     //val sc = new SparkContext(conf)

    val spark = SparkSession.builder()
      .appName("SerializerTypeDemo")
      .master("local[6]")
      //.config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      .config(conf)
      .getOrCreate()


    val persons = new ArrayBuffer[Person]
    for (i <- 1 to 1000000) {
      persons += (Person("name" + i, 10 + i, "male", "haerbin"))
    }


    val personrdd=spark.sparkContext.parallelize(persons)

    personrdd.persist(StorageLevel.MEMORY_ONLY)//95M 10.353602 s
    //personrdd.persist(StorageLevel.MEMORY_ONLY_SER)// 未注册 75M   Java默认32.6M   注册之后 27.6M  11.141196 s
    personrdd.count()


    while(true){
      val a ="b"
    }



  }
}
